package chapter07.chainOfResponsibility;
public class LeaveApprovalTest {
	public static void main(String[] args) {
		//组装责任链  
		Leader teacher1 = new ClassAdviser();
		Leader teacher2 = new DepartmentHead();
		Leader teacher3 = new Dean();
		//Leader teacher4 = new DeanOfStudies();
		teacher1.setNext(teacher2); 
		teacher2.setNext(teacher3); 
		//teacher3.setNext(teacher4); 
        //提交请求  
		teacher1.handleRequest(8); 
	}
}
//抽象处理者：领导类
abstract class Leader{
	private Leader next;
	public void setNext(Leader next){
		this.next = next;  
    } 
    public Leader getNext(){  
        return next;  
    }    
    //处理请求的方法
    public abstract void handleRequest(int LeaveDays);        
}
//具体处理者1：班主任类
class ClassAdviser extends Leader {
	public void handleRequest(int LeaveDays){
		if(LeaveDays<=2)  
        {
			System.out.println("班主任批准您请假" + LeaveDays + "天。");        
        }else{
        	if(getNext() != null)  
            {
        		getNext().handleRequest(LeaveDays);              
            }else{
          	    System.out.println("请假天数太多，没有人批准该假条！"); 
            }
        }  
    }  
}
//具体处理者2：系主任类
class DepartmentHead extends Leader {
	public void handleRequest(int LeaveDays){
		if(LeaveDays<=7)  
        {
			System.out.println("系主任批准您请假" + LeaveDays + "天。");        
        }else{
        	if(getNext() != null)  
            {
      		    getNext().handleRequest(LeaveDays);              
            }else{
        	    System.out.println("请假天数太多，没有人批准该假条！"); 
           }
        }  
    }  
}
//具体处理者3：院长类
class Dean extends Leader {
	public void handleRequest(int LeaveDays){
		if(LeaveDays<=10)  
      {
			System.out.println("院长批准您请假" + LeaveDays + "天。");        
      }else{
      	if(getNext() != null)  
          {
    		    getNext().handleRequest(LeaveDays);              
          }else{
      	    System.out.println("请假天数太多，没有人批准该假条！"); 
         }
      }  
  }  
}
//具体处理者4：教务处长类
class DeanOfStudies extends Leader {
	public void handleRequest(int LeaveDays){
		if(LeaveDays<=20)  
      {
			System.out.println("教务处长批准您请假" + LeaveDays + "天。");        
      }else{
      	if(getNext() != null)  
          {
    		    getNext().handleRequest(LeaveDays);           
          }else{
      	    System.out.println("请假天数太多，没有人批准该假条！"); 
         }
      }  
  }  
}